#pragma once
#include <QtCore/QVariant>
#include <QtCore/QStack>
#include <QtCore/QSet>
#include <QtXml/QDomElement>
#include <QtXml/QXmlStreamWriter>

class Trace
{
public:
	Trace();
	Trace(int ordinal, int amount);
	Trace(const Trace& other);
	
	bool parseContent(const QDomElement& element);
	void writeContent(QXmlStreamWriter& writer) const;

	QString containsToString() const;
	void stringToContains(const QString & str);

	Trace& combine(const Trace& other);

	bool isPartial() const; //partial composite
	QSet<int> contains() const;
	int mount() const;
	void setMount(int mount){ mAmount = mount; }
	bool isComplete() const;
	

private:
	void addItem(int i);

	QSet<int> mItems;
	int  mAmount;
};

class Token : public QVariant
{
public:
	Token(){}
	Token(const QVariant& var);
	virtual ~Token(void);

	bool parseContent(const QDomElement& element);
	void writeContent(QXmlStreamWriter& writer) const;

	void setVariant(const QVariant & var);

	//split this token to a list of tokens
	void split(QList<Token*>& tokens);
	//Token& combine(const QList<Token*>& tokens); //should support part combine 

	void setTraceStack(const QStack<Trace>& traceStack);
	const QStack<Trace>& trace() const;
	void pushTrace(const Trace& trace);
	void popTrace();
	Trace& topTrace();

private:
	QStack<Trace> mTraceStack;
};
